import json
import torch
from torch.utils.tensorboard import SummaryWriter


with open("./metrics/libra_r-cnn/coco/20210210_183031.log.json") as json_file:
    data = json.load(json_file)
    writers = [i for i in range(8)]
    data_col = ['lr', 'memory', 'loss_rpn_cls', 'loss_rpn_bbox', 'loss_cls', 'acc', 'loss_bbox', 'loss']
    # print(data)
    for j in range(len(writers)):
        writers[j] = SummaryWriter()
        for i in range(len(data)):
            if data[i]['iter'] <= 7300:
                writers[j].add_scalar(f'{data_col[j]}', data[i][data_col[j]], data[i]['iter']+(data[i]['epoch']-1)*7330)
print("finish")